import Vue from "vue";
import Vuex from "vuex";

import getters from "./getters";

Vue.use(Vuex);

// 动态添加模块
const modulesFiles = require.context("./modules", true, /\.js$/);
const modules = {};
modulesFiles.keys().map((key) => {
  const keys = key.replace(/(\.\/|\.js)/g, "");
  modules[keys.split("/").pop()] = {
    namespaced: true,
    ...modulesFiles(key).default,
  };
});
export default function (pagesModules = {}) {
  return new Vuex.Store({
    modules: {
      ...modules,
      ...pagesModules,
    },
    getters,
  });
}
